/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.basics.editor.model.document;

import java.util.Map;

import com.genia.toolbox.basics.i18n.I18nMessage;

/**
 * A variable model.
 */
public class VariableModel
{

  /**
   * Whether the value is mandatory.
   */
  private boolean isMandatory = false;

  /**
   * The variable name.
   */
  private String name = null;

  /**
   * The variable description.
   */
  private I18nMessage description = null;

  /**
   * The variable value.
   */
  private String value = null;

  /**
   * The variable possible values.
   */
  private Map<I18nMessage, String> values = null;

  /**
   * Whether the value should have the type Long.
   */
  private boolean isLongValue = false;

  /**
   * Whether the value should have the type Boolean.
   */
  private boolean isBooleanValue = false;



  /**
   * Constructor.
   * 
   * @param name
   *          the variable name.
   * @param value
   *          the variable value.
   */
  public VariableModel(String name, String value)
  {
    super();
    this.name = name;
    this.value = value;
  }



  /**
   * Constructor.
   * 
   * @param name
   *          the variable name.
   * @param description
   *          the variable description.
   * @param value
   *          the variable value.
   * @param values
   *          the variable values.
   * @param isMandatory
   *          the variable isMandatory.
   * @param isLongValue
   *          the variable isLongValue.
   */
  public VariableModel(String name, I18nMessage description, String value, Map<I18nMessage, String> values, boolean isMandatory, boolean isLongValue)
  {
    super();
    this.name = name;
    this.description = description;
    this.value = value;
    this.values = values;
    this.isMandatory = isMandatory;
    this.isLongValue = isLongValue;
  }



  /**
   * Constructor.
   * 
   * @param name
   *          the variable name.
   * @param description
   *          the variable description.
   * @param value
   *          the variable value.
   * @param values
   *          the variable values.
   * @param isMandatory
   *          the variable isMandatory.
   * @param isLongValue
   *          the variable isLongValue.
   * @param isBooleanValue
   *          the variable isBooleanValue.
   */
  public VariableModel(String name, I18nMessage description, String value, Map<I18nMessage, String> values, boolean isMandatory, boolean isLongValue, boolean isBooleanValue)
  {
    super();
    this.name = name;
    this.description = description;
    this.value = value;
    this.values = values;
    this.isMandatory = isMandatory;
    this.isLongValue = isLongValue;
    this.isBooleanValue = isBooleanValue;
  }



  /**
   * Get the variable description.
   * 
   * @return the variable description.
   */
  public I18nMessage getDescription()
  {
    return this.description;
  }



  /**
   * Set the variable description.
   * 
   * @param description
   *          the variable description.
   */
  public void setDescription(I18nMessage description)
  {
    this.description = description;
  }



  /**
   * Get whether the variable is mandatory.
   * 
   * @return whether the variable is mandatory.
   */
  public boolean isMandatory()
  {
    return this.isMandatory;
  }



  /**
   * Set whether the variable is mandatory.
   * 
   * @param isMandatory
   *          whether the variable is mandatory.
   */
  public void setMandatory(boolean isMandatory)
  {
    this.isMandatory = isMandatory;
  }



  /**
   * Get the variable name.
   * 
   * @return the variable name.
   */
  public String getName()
  {
    return this.name;
  }



  /**
   * Set the variable name.
   * 
   * @param name
   *          the variable name.
   */
  public void setName(String name)
  {
    this.name = name;
  }



  /**
   * Get the variable value.
   * 
   * @return the variable value.
   */
  public String getValue()
  {
    return this.value;
  }



  /**
   * Set the variable value.
   * 
   * @param value
   *          the variable value.
   */
  public void setValue(String value)
  {
    this.value = value;
  }



  /**
   * Get the variable values.
   * 
   * @return the variable values.
   */
  public Map<I18nMessage, String> getValues()
  {
    return this.values;
  }



  /**
   * Set the variable values.
   * 
   * @param values
   *          the variable values.
   */
  public void setValues(Map<I18nMessage, String> values)
  {
    this.values = values;
  }



  /**
   * Get whether the value should be a Long.
   * 
   * @return whether the value should be a Long.
   */
  public boolean isLongValue()
  {
    return this.isLongValue;
  }



  /**
   * Set whether the value should be a Long.
   * 
   * @param isLongValue
   *          whether the value should be a Long.
   */
  public void setLongValue(boolean isLongValue)
  {
    this.isLongValue = isLongValue;
  }



  /**
   * Get whether the value should be a Boolean.
   * 
   * @return whether the value should be a Boolean.
   */
  public boolean isBooleanValue()
  {
    return this.isBooleanValue;
  }



  /**
   * Set whether the value should be a Boolean.
   * 
   * @param isBooleanValue
   *          whether the value should be a Boolean.
   */
  public void setBooleanValue(boolean isBooleanValue)
  {
    this.isBooleanValue = isBooleanValue;
  }



  /**
   * Get whether the variable has possible values.
   * 
   * @return whether the variable has possible values.
   */
  public boolean hasValues()
  {
    boolean hasValues = false;
    if (this.values != null && !this.values.isEmpty()) {
      hasValues = true;
    }
    return hasValues;
  }



  /**
   * Check whether the hole value is valid.
   * 
   * @return whether the hole value is valid.
   */
  public boolean accept()
  {
    boolean isOK = true;
    if (this.isMandatory) {
      if (this.getValue() == null || this.getValue().trim().length() == 0) {
        isOK = false;
      }
    }
    return isOK;
  }

}
